{% extends "base.html" %}

{% block content %}
<div class="row fade-in">
    <div class="col-lg-12 mb-4">
        <div class="card shadow-sm">
            <div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
                <h4 class="m-0 font-weight-bold text-primary"><i class="bi bi-people me-2"></i>用户管理</h4>
            </div>
            <div class="card-body">
                <div class="table-responsive user-table">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>用户名</th>
                                <th>邮箱</th>
                                <th>角色</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for user in users %}
                            <tr>
                                <td>{{ user.id }}</td>
                                <td>
                                    <div class="d-flex align-items-center">
                                        <img src="https://ui-avatars.com/api/?name={{ user.username }}&background=4e73df&color=fff&size=32" 
                                             class="rounded-circle me-2" alt="用户头像">
                                        <span>{{ user.username }}</span>
                                    </div>
                                </td>
                                <td>{{ user.email }}</td>
                                <td>
                                    {% if user.is_admin %}
                                        <span class="badge bg-success rounded-pill"><i class="bi bi-star-fill me-1"></i>管理员</span>
                                    {% else %}
                                        <span class="badge bg-secondary rounded-pill"><i class="bi bi-person me-1"></i>普通用户</span>
                                    {% endif %}
                                </td>
                                <td>
                                    {% if user.is_admin %}
                                        <a href="{{ url_for('admin.demote_user', user_id=user.id) }}" class="btn btn-sm btn-warning">
                                            <i class="bi bi-arrow-down-circle me-1"></i>取消管理员
                                        </a>
                                    {% else %}
                                        <a href="{{ url_for('admin.promote_user', user_id=user.id) }}" class="btn btn-sm btn-success">
                                            <i class="bi bi-arrow-up-circle me-1"></i>设为管理员
                                        </a>
                                    {% endif %}
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}